// MythtvGadget.js
//


Type.createNamespace('MythtvGadget');

////////////////////////////////////////////////////////////////////////////////
// MythtvGadget.MythtvStatus

MythtvGadget.MythtvStatus = function MythtvGadget_MythtvStatus() {
}
MythtvGadget.MythtvStatus.getStatus = function MythtvGadget_MythtvStatus$getStatus(callback) {
    /// <param name="callback" type="MythtvGadget.GetStatusCompletedCallback">
    /// </param>
    var uri = MythtvGadget._settings.get_statusUrl() + 'xml';
    try {
        var searchRequest = ScriptFX.Net.HTTPRequest.createRequest(uri, ScriptFX.Net.HTTPVerb.GET);
        searchRequest.invoke(Delegate.create(null, function(request, context) {
            var searchResult = new MythtvGadget.MythtvStatusResult(request.get_response());
            callback.invoke(searchResult);
        }), null);
    }
    catch ($e1) {
        var cp = $('contentpanel');
        cp.innerHTML = 'Error';
    }
}


////////////////////////////////////////////////////////////////////////////////
// MythtvGadget.MythtvStatusResult

MythtvGadget.MythtvStatusResult = function MythtvGadget_MythtvStatusResult(response) {
    /// <param name="response" type="ScriptFX.Net.IHTTPResponse">
    /// </param>
    /// <field name="success" type="Boolean">
    /// </field>
    /// <field name="successMessage" type="String">
    /// </field>
    /// <field name="mythVersion" type="String">
    /// </field>
    /// <field name="updated" type="Date">
    /// </field>
    /// <field name="encodersIdle" type="Number" integer="true">
    /// </field>
    /// <field name="encodersBusy" type="Number" integer="true">
    /// </field>
    /// <field name="guideDays" type="Number" integer="true">
    /// </field>
    /// <field name="guideStatus" type="String">
    /// </field>
    /// <field name="driveTotalUsed" type="Number" integer="true">
    /// </field>
    /// <field name="driveTotalFree" type="Number" integer="true">
    /// </field>
    /// <field name="programs" type="Array" elementType="Program">
    /// </field>
    /// <field name="parseOk" type="Boolean">
    /// </field>
    /// <field name="debugMessage" type="String">
    /// </field>
    this.success = (response.get_statusCode() === ScriptFX.Net.HTTPStatusCode.OK);
    if (!this.success) {
        this.debugMessage = 'Request Failed';
    }
    else {
        this._parseResponse(response);
    }
}
MythtvGadget.MythtvStatusResult.prototype = {
    success: false,
    successMessage: null,
    mythVersion: null,
    updated: null,
    encodersIdle: 0,
    encodersBusy: 0,
    guideDays: 0,
    guideStatus: null,
    driveTotalUsed: 0,
    driveTotalFree: 0,
    programs: null,
    
    get_driveTotalFreeGb: function MythtvGadget_MythtvStatusResult$get_driveTotalFreeGb() {
        /// <value type="Number" integer="true"></value>
        return Math.floor(this.driveTotalFree / 1024);
    },
    
    get_driveTotalUsedPercent: function MythtvGadget_MythtvStatusResult$get_driveTotalUsedPercent() {
        /// <value type="Number" integer="true"></value>
        return Math.floor(100 * (this.driveTotalUsed / (this.driveTotalUsed + this.driveTotalFree)));
    },
    
    parseOk: false,
    debugMessage: null,
    
    _parseResponse: function MythtvGadget_MythtvStatusResult$_parseResponse(response) {
        /// <param name="response" type="ScriptFX.Net.IHTTPResponse">
        /// </param>
        try {
            var dom;
            dom = response.getXML();
            if (!dom) {
                dom = XMLDocumentParser.parse(response.getText());
            }
            var nodStatus = dom.selectSingleNode('/Status');
            this.mythVersion = nodStatus.attributes.getNamedItem('version').text;
            if (nodStatus.attributes.getNamedItem('ISODate')) {
                this.updated = MythtvGadget._utilities.xmlDateTimeParser(nodStatus.attributes.getNamedItem('ISODate').text);
            }
            else {
                this.updated = Date.get_now();
            }
            var nlEncoders = dom.selectNodes('/Status/Encoders/Encoder');
            for (var i = 0; i < nlEncoders.length; i++) {
                if (nlEncoders[i].attributes.getNamedItem('state').text === '0') {
                    this.encodersIdle++;
                }
                else {
                    this.encodersBusy++;
                }
            }
            var nlPrograms = dom.selectNodes('/Status/Scheduled/Program');
            this.programs = new Array(nlPrograms.length);
            for (var i = 0; i < nlPrograms.length; i++) {
                var p = new MythtvGadget.Program(nlPrograms[i]);
                this.programs[i] = p;
            }
            var nodGuide = dom.selectSingleNode('/Status/MachineInfo/Guide');
            this.guideDays = Number.parse(nodGuide.attributes.getNamedItem('guideDays').text);
            this.guideStatus = nodGuide.attributes.getNamedItem('status').text;
            var nodStorage = dom.selectSingleNode('/Status/MachineInfo/Storage');
            var mythVersionNumber = Number.parse(this.mythVersion.split('.')[1]);
            if (mythVersionNumber >= 22) {
                var nodTotal = nodStorage.selectSingleNode('Group[@dir=\"TotalDiskSpace\"]');
                this.driveTotalFree = Number.parse(nodTotal.attributes.getNamedItem('free').text);
                this.driveTotalUsed = Number.parse(nodTotal.attributes.getNamedItem('used').text);
            }
            else if (mythVersionNumber === 21) {
                this.driveTotalFree = Number.parse(nodStorage.attributes.getNamedItem('drive_total_free').text);
                this.driveTotalUsed = Number.parse(nodStorage.attributes.getNamedItem('drive_total_used').text);
            }
            else {
                var nodTotalFree = nodStorage.attributes.getNamedItem('_total_free');
                if (nodTotalFree) {
                    this.driveTotalFree = Number.parse(nodStorage.attributes.getNamedItem('_total_free').text);
                    this.driveTotalUsed = Number.parse(nodStorage.attributes.getNamedItem('_total_used').text);
                }
            }
            this.parseOk = true;
        }
        catch (ex) {
            this.debugMessage = 'Parse Failed<br>' + ex.message;
        }
    }
}


////////////////////////////////////////////////////////////////////////////////
// MythtvGadget.Program

MythtvGadget.Program = function MythtvGadget_Program(nod) {
    /// <param name="nod" type="XMLNode">
    /// </param>
    /// <field name="title" type="String">
    /// </field>
    /// <field name="subTitle" type="String">
    /// </field>
    /// <field name="description" type="String">
    /// </field>
    /// <field name="channelCallSign" type="String">
    /// </field>
    /// <field name="startTime" type="Date">
    /// </field>
    /// <field name="endTime" type="Date">
    /// </field>
    this.subTitle = String.Empty;
    try {
        var tempNod;
        this.title = nod.attributes.getNamedItem('title').text;
        tempNod = nod.attributes.getNamedItem('subTitle');
        if (tempNod) {
            this.subTitle = tempNod.text;
        }
        this.description = nod.text;
        tempNod = nod.selectSingleNode('Channel');
        this.channelCallSign = tempNod.attributes.getNamedItem('callSign').text;
        this.startTime = MythtvGadget._utilities.xmlDateTimeParser(nod.attributes.getNamedItem('startTime').text);
        this.endTime = MythtvGadget._utilities.xmlDateTimeParser(nod.attributes.getNamedItem('endTime').text);
    }
    catch ($e1) {
    }
}
MythtvGadget.Program.prototype = {
    title: null,
    description: null,
    channelCallSign: null,
    startTime: null,
    endTime: null
}


////////////////////////////////////////////////////////////////////////////////
// MythtvGadget.GadgetScriptlet

MythtvGadget.GadgetScriptlet = function MythtvGadget_GadgetScriptlet() {
    /// <field name="timer" type="Number" integer="true">
    /// </field>
    /// <field name="_callInProgress" type="Boolean">
    /// </field>
    /// <field name="_flyoutVisible" type="Boolean">
    /// </field>
    Gadget.settingsUI = 'Settings.htm';
    Gadget.onDock = Delegate.create(this, this._onDock);
    Gadget.onUndock = Delegate.create(this, this._onUndock);
    Gadget.Flyout.file = 'Flyout.htm';
    Gadget.Flyout.onShow = Delegate.create(this, this._onFlyoutShow);
    Gadget.Flyout.onHide = Delegate.create(this, this._onFlyoutHide);
    Gadget.onSettingsClosed = Delegate.create(this, this._onSettingsClosed);
    this._updateDockedState();
    this.timer = window.setTimeout(Delegate.create(this, this._doUpdate), 250);
}
MythtvGadget.GadgetScriptlet.main = function MythtvGadget_GadgetScriptlet$main(arguments) {
    /// <param name="arguments" type="Object">
    /// </param>
    var scriptlet = new MythtvGadget.GadgetScriptlet();
}
MythtvGadget.GadgetScriptlet.prototype = {
    timer: 0,
    _callInProgress: false,
    _flyoutVisible: false,
    
    _onSettingsClosed: function MythtvGadget_GadgetScriptlet$_onSettingsClosed() {
        this._updateDockedState();
        this._doUpdate();
    },
    
    _doUpdate: function MythtvGadget_GadgetScriptlet$_doUpdate() {
        if (!String.isNullOrEmpty(MythtvGadget._settings.get_statusUrl())) {
            var config = $('config');
            config.className = 'set';
            if (!this._callInProgress) {
                this._callInProgress = true;
                MythtvGadget.MythtvStatus.getStatus(Delegate.create(this, this.statusCompletedCallback));
            }
        }
        else {
            var config = $('config');
            config.className = 'unset';
        }
    },
    
    _setWaitForUpdate: function MythtvGadget_GadgetScriptlet$_setWaitForUpdate() {
        if (this.timer) {
            window.clearInterval(this.timer);
        }
        this.timer = window.setTimeout(Delegate.create(this, this._doUpdate), MythtvGadget._settings.get_updateInterval() * 1000);
    },
    
    statusCompletedCallback: function MythtvGadget_GadgetScriptlet$statusCompletedCallback(result) {
        /// <param name="result" type="MythtvGadget.MythtvStatusResult">
        /// </param>
        this._callInProgress = false;
        var mythwebLink = $('mythweb');
        var upcomingLink = $('upcomingText');
        var guideText = $('guideText');
        if (!String.isNullOrEmpty(MythtvGadget._settings.get_mythwebUrl())) {
            mythwebLink.href = MythtvGadget._settings.get_mythwebUrl();
            upcomingLink.href = MythtvGadget._settings.get_mythwebUrl() + 'tv/upcoming';
            guideText.href = MythtvGadget._settings.get_mythwebUrl() + 'tv/list';
        }
        else {
            mythwebLink.href = '#';
            upcomingLink.href = '';
            guideText.href = '';
        }
        if (!result.success || !result.parseOk) {
            var error = $('error');
            error.className = 'error';
            error.innerHTML = 'Update Failed<br>' + result.debugMessage;
        }
        else {
            var error = $('error');
            error.className = 'ok';
            var dUpdated = $('updated');
            dUpdated.innerText = result.updated.format('HH:mm');
            var dEncoders = $('encData');
            dEncoders.innerHTML = String.format('{0} idle, {1} busy', result.encodersIdle, result.encodersBusy);
            var dGuideDays = $('guideDays');
            dGuideDays.innerHTML = String.format('{0} days', result.guideDays);
            if (result.guideDays < MythtvGadget._settings.get_guideWarningDays()) {
                dGuideDays.className = 'warning';
            }
            else {
                dGuideDays.className = '';
            }
            var dGuideResult = $('guideResult');
            if (result.guideStatus.length > 12) {
                dGuideResult.innerHTML = result.guideStatus.substring(0, 12);
            }
            else {
                dGuideResult.innerHTML = result.guideStatus;
            }
            if (result.guideStatus !== 'Successful.') {
                dGuideResult.className = 'warning';
            }
            else {
                dGuideResult.className = '';
            }
            var dDiskUsed = $('diskUsed');
            dDiskUsed.innerHTML = String.format('{0}% used', result.get_driveTotalUsedPercent());
            var dDiskFree = $('diskFree');
            dDiskFree.innerHTML = String.format('({0}Gb Free)', result.get_driveTotalFreeGb());
            var dUpcoming = $('upcoming');
            dUpcoming.innerHTML = '';
            for (var i = 0; i < result.programs.length; i++) {
                dUpcoming.innerHTML += String.format('{0}<br/><span class=\"ucSmall\">&nbsp;{1}{2}{3}</span><br/>', result.programs[i].title, result.programs[i].channelCallSign, (MythtvGadget._settings.get_dateOnNewLine()) ? '<br>&nbsp;' : ', ', result.programs[i].startTime.format(MythtvGadget._settings.get_dateFormat()));
            }
        }
        this._setWaitForUpdate();
    },
    
    _onFlyoutHide: function MythtvGadget_GadgetScriptlet$_onFlyoutHide() {
        this._flyoutVisible = false;
    },
    
    _onFlyoutShow: function MythtvGadget_GadgetScriptlet$_onFlyoutShow() {
        this._flyoutVisible = true;
    },
    
    _onUndock: function MythtvGadget_GadgetScriptlet$_onUndock() {
        this._updateDockedState();
    },
    
    _onDock: function MythtvGadget_GadgetScriptlet$_onDock() {
        this._updateDockedState();
    },
    
    _updateDockedState: function MythtvGadget_GadgetScriptlet$_updateDockedState() {
        var body = document.body;
        if (Gadget.docked) {
            ScriptFX.UI.Element.removeCSSClass(body, 'undocked');
            ScriptFX.UI.Element.addCSSClass(body, 'docked');
        }
        else {
            ScriptFX.UI.Element.addCSSClass(body, 'undocked');
            ScriptFX.UI.Element.removeCSSClass(body, 'docked');
        }
        body.style.height = MythtvGadget._settings.get_gadgetHeight().toString();
    }
}


////////////////////////////////////////////////////////////////////////////////
// MythtvGadget.FlyoutScriptlet

MythtvGadget.FlyoutScriptlet = function MythtvGadget_FlyoutScriptlet() {
}
MythtvGadget.FlyoutScriptlet.main = function MythtvGadget_FlyoutScriptlet$main(arguments) {
    /// <param name="arguments" type="Object">
    /// </param>
    var scriptlet = new MythtvGadget.FlyoutScriptlet();
}


////////////////////////////////////////////////////////////////////////////////
// MythtvGadget._settings

MythtvGadget._settings = function MythtvGadget__settings() {
    /// <field name="_settingS_URL" type="String" static="true">
    /// </field>
    /// <field name="_mythweB_URL" type="String" static="true">
    /// </field>
    /// <field name="_settingS_INTERVAL" type="String" static="true">
    /// </field>
    /// <field name="_guidE_DAYS_WARNING" type="String" static="true">
    /// </field>
    /// <field name="_gadgeT_HEIGHT" type="String" static="true">
    /// </field>
    /// <field name="_datE_FORMAT" type="String" static="true">
    /// </field>
    /// <field name="_datE_ON_NEWLINE" type="String" static="true">
    /// </field>
    /// <field name="defaulT_HEIGHT" type="Number" integer="true" static="true">
    /// </field>
    /// <field name="defaulT_DATE_FORMAT" type="String" static="true">
    /// </field>
}
MythtvGadget._settings.get_statusUrl = function MythtvGadget__settings$get_statusUrl() {
    /// <value type="String"></value>
    return MythtvGadget._settings._getUrlWithTerminatingSlash(MythtvGadget._settings._settingS_URL);
}
MythtvGadget._settings.set_statusUrl = function MythtvGadget__settings$set_statusUrl(value) {
    /// <value type="String"></value>
    Gadget.Settings.writeString(MythtvGadget._settings._settingS_URL, value);
    return value;
}
MythtvGadget._settings.get_mythwebUrl = function MythtvGadget__settings$get_mythwebUrl() {
    /// <value type="String"></value>
    return MythtvGadget._settings._getUrlWithTerminatingSlash(MythtvGadget._settings._mythweB_URL);
}
MythtvGadget._settings.set_mythwebUrl = function MythtvGadget__settings$set_mythwebUrl(value) {
    /// <value type="String"></value>
    Gadget.Settings.writeString(MythtvGadget._settings._mythweB_URL, value);
    return value;
}
MythtvGadget._settings._getUrlWithTerminatingSlash = function MythtvGadget__settings$_getUrlWithTerminatingSlash(settingName) {
    /// <param name="settingName" type="String">
    /// </param>
    /// <returns type="String"></returns>
    var url = Gadget.Settings.readString(settingName);
    if (!url.endsWith('/') && !String.isNullOrEmpty(url)) {
        url += '/';
    }
    return url;
}
MythtvGadget._settings.get_updateInterval = function MythtvGadget__settings$get_updateInterval() {
    /// <value type="Number" integer="true"></value>
    var interval = Gadget.Settings.readString(MythtvGadget._settings._settingS_INTERVAL);
    if (String.isNullOrEmpty(interval)) {
        return 300;
    }
    else {
        return Number.parse(interval);
    }
}
MythtvGadget._settings.set_updateInterval = function MythtvGadget__settings$set_updateInterval(value) {
    /// <value type="Number" integer="true"></value>
    Gadget.Settings.writeString(MythtvGadget._settings._settingS_INTERVAL, value.toString());
    return value;
}
MythtvGadget._settings.get_guideWarningDays = function MythtvGadget__settings$get_guideWarningDays() {
    /// <value type="Number" integer="true"></value>
    var days = Gadget.Settings.readString(MythtvGadget._settings._guidE_DAYS_WARNING);
    if (String.isNullOrEmpty(days)) {
        return 7;
    }
    else {
        return Number.parse(days);
    }
}
MythtvGadget._settings.set_guideWarningDays = function MythtvGadget__settings$set_guideWarningDays(value) {
    /// <value type="Number" integer="true"></value>
    Gadget.Settings.writeString(MythtvGadget._settings._guidE_DAYS_WARNING, value.toString());
    return value;
}
MythtvGadget._settings.get_gadgetHeight = function MythtvGadget__settings$get_gadgetHeight() {
    /// <value type="Number" integer="true"></value>
    var height = Gadget.Settings.read(MythtvGadget._settings._gadgeT_HEIGHT);
    if (!height) {
        height = MythtvGadget._settings.defaulT_HEIGHT;
    }
    return height;
}
MythtvGadget._settings.set_gadgetHeight = function MythtvGadget__settings$set_gadgetHeight(value) {
    /// <value type="Number" integer="true"></value>
    Gadget.Settings.write(MythtvGadget._settings._gadgeT_HEIGHT, value);
    return value;
}
MythtvGadget._settings.get_dateFormat = function MythtvGadget__settings$get_dateFormat() {
    /// <value type="String"></value>
    var dateFormat = Gadget.Settings.readString(MythtvGadget._settings._datE_FORMAT);
    if (String.isNullOrEmpty(dateFormat)) {
        dateFormat = MythtvGadget._settings.defaulT_DATE_FORMAT;
    }
    return dateFormat;
}
MythtvGadget._settings.set_dateFormat = function MythtvGadget__settings$set_dateFormat(value) {
    /// <value type="String"></value>
    Gadget.Settings.writeString(MythtvGadget._settings._datE_FORMAT, value);
    return value;
}
MythtvGadget._settings.get_dateOnNewLine = function MythtvGadget__settings$get_dateOnNewLine() {
    /// <value type="Boolean"></value>
    return Boolean.parse(Gadget.Settings.readString(MythtvGadget._settings._datE_ON_NEWLINE));
}
MythtvGadget._settings.set_dateOnNewLine = function MythtvGadget__settings$set_dateOnNewLine(value) {
    /// <value type="Boolean"></value>
    Gadget.Settings.writeString(MythtvGadget._settings._datE_ON_NEWLINE, value.toString());
    return value;
}


////////////////////////////////////////////////////////////////////////////////
// MythtvGadget.SettingsScriptlet

MythtvGadget.SettingsScriptlet = function MythtvGadget_SettingsScriptlet() {
    /// <field name="_url" type="Object" domElement="true">
    /// </field>
    /// <field name="_mythwebUrl" type="Object" domElement="true">
    /// </field>
    /// <field name="_interval" type="Object" domElement="true">
    /// </field>
    /// <field name="_guideDays" type="Object" domElement="true">
    /// </field>
    /// <field name="_gadgetHeight" type="Object" domElement="true">
    /// </field>
    /// <field name="_dateFormat" type="Object" domElement="true">
    /// </field>
    /// <field name="_dateOnNewLine" type="Object" domElement="true">
    /// </field>
    this._url = $('mythStatusUrl');
    this._mythwebUrl = $('mythwebUrl');
    this._interval = $('updateInterval');
    this._guideDays = $('guideDays');
    this._gadgetHeight = $('gadgetHeight');
    this._dateFormat = $('dateFormat');
    this._dateOnNewLine = $('dateOnNewLine');
    this._url.value = MythtvGadget._settings.get_statusUrl();
    this._mythwebUrl.value = MythtvGadget._settings.get_mythwebUrl();
    for (var i = 0; i < this._interval.options.length; i++) {
        if ((this._interval.options[i]).value === MythtvGadget._settings.get_updateInterval().toString()) {
            (this._interval.options[i]).selected = true;
        }
    }
    for (var i = 0; i < this._guideDays.options.length; i++) {
        if ((this._guideDays.options[i]).value === MythtvGadget._settings.get_guideWarningDays().toString()) {
            (this._guideDays.options[i]).selected = true;
        }
    }
    this._gadgetHeight.value = MythtvGadget._settings.get_gadgetHeight().toString();
    for (var i = 0; i < this._dateFormat.options.length; i++) {
        if ((this._dateFormat.options[i]).value === MythtvGadget._settings.get_dateFormat()) {
            (this._dateFormat.options[i]).selected = true;
        }
    }
    this._dateOnNewLine.checked = MythtvGadget._settings.get_dateOnNewLine();
    Gadget.onSettingsClosing = Delegate.create(this, this._settingsClosing);
}
MythtvGadget.SettingsScriptlet.main = function MythtvGadget_SettingsScriptlet$main(arguments) {
    /// <param name="arguments" type="Object">
    /// </param>
    var scriptlet = new MythtvGadget.SettingsScriptlet();
}
MythtvGadget.SettingsScriptlet.prototype = {
    _url: null,
    _mythwebUrl: null,
    _interval: null,
    _guideDays: null,
    _gadgetHeight: null,
    _dateFormat: null,
    _dateOnNewLine: null,
    
    _settingsClosing: function MythtvGadget_SettingsScriptlet$_settingsClosing(e) {
        /// <param name="e" type="GadgetSettingsEvent">
        /// </param>
        if (e.closeAction === GadgetSettingsCloseAction.commit) {
            MythtvGadget._settings.set_statusUrl(this._url.value);
            MythtvGadget._settings.set_mythwebUrl(this._mythwebUrl.value);
            for (var i = 0; i < this._interval.options.length; i++) {
                if ((this._interval.options[i]).selected) {
                    MythtvGadget._settings.set_updateInterval(Number.parse((this._interval.options[i]).value));
                }
            }
            for (var i = 0; i < this._guideDays.options.length; i++) {
                if ((this._guideDays.options[i]).selected) {
                    MythtvGadget._settings.set_guideWarningDays(Number.parse((this._guideDays.options[i]).value));
                }
            }
            var height = MythtvGadget._settings.defaulT_HEIGHT;
            try {
                height = Number.parse(this._gadgetHeight.value);
            }
            catch ($e1) {
            }
            MythtvGadget._settings.set_gadgetHeight(height);
            for (var i = 0; i < this._dateFormat.options.length; i++) {
                if ((this._dateFormat.options[i]).selected) {
                    MythtvGadget._settings.set_dateFormat((this._dateFormat.options[i]).value);
                }
            }
            MythtvGadget._settings.set_dateOnNewLine(this._dateOnNewLine.checked);
        }
    }
}


////////////////////////////////////////////////////////////////////////////////
// MythtvGadget._utilities

MythtvGadget._utilities = function MythtvGadget__utilities() {
}
MythtvGadget._utilities.xmlDateTimeParser = function MythtvGadget__utilities$xmlDateTimeParser(value) {
    /// <param name="value" type="String">
    /// </param>
    /// <returns type="Date"></returns>
    try {
        var parts = value.split('T');
        var dateParts = parts[0].split('-');
        var year = MythtvGadget._utilities._stringToInt(dateParts[0]);
        var month = MythtvGadget._utilities._stringToInt(dateParts[1]);
        var day = MythtvGadget._utilities._stringToInt(dateParts[2]);
        var timeParts = parts[1].split(':');
        var hour = MythtvGadget._utilities._stringToInt(timeParts[0]);
        var minute = MythtvGadget._utilities._stringToInt(timeParts[1]);
        var second = MythtvGadget._utilities._stringToInt(timeParts[2]);
        var dt = new Date(year, month - 1, day, hour, minute, second);
        return dt;
    }
    catch ($e1) {
        return null;
    }
}
MythtvGadget._utilities._stringToInt = function MythtvGadget__utilities$_stringToInt(value) {
    /// <param name="value" type="String">
    /// </param>
    /// <returns type="Number" integer="true"></returns>
    while (value.startsWith('0')) {
        value = value.substr(1);
    }
    var n = Number.parse(value);
    return n;
}


MythtvGadget.MythtvStatus.createClass('MythtvGadget.MythtvStatus');
MythtvGadget.MythtvStatusResult.createClass('MythtvGadget.MythtvStatusResult');
MythtvGadget.Program.createClass('MythtvGadget.Program');
MythtvGadget.GadgetScriptlet.createClass('MythtvGadget.GadgetScriptlet');
MythtvGadget.FlyoutScriptlet.createClass('MythtvGadget.FlyoutScriptlet');
MythtvGadget._settings.createClass('MythtvGadget._settings');
MythtvGadget.SettingsScriptlet.createClass('MythtvGadget.SettingsScriptlet');
MythtvGadget._utilities.createClass('MythtvGadget._utilities');
if (document.body.id === 'gadget') {
    ScriptFX.Application.current.run(MythtvGadget.GadgetScriptlet, null);
}
if (document.body.id === 'gadgetFlyout') {
    ScriptFX.Application.current.run(MythtvGadget.FlyoutScriptlet, null);
}
MythtvGadget._settings._settingS_URL = 'MythStatusUrl';
MythtvGadget._settings._mythweB_URL = 'MythwebUrl';
MythtvGadget._settings._settingS_INTERVAL = 'UpdateInterval';
MythtvGadget._settings._guidE_DAYS_WARNING = 'GuideWarning';
MythtvGadget._settings._gadgeT_HEIGHT = 'GadgetHeight';
MythtvGadget._settings._datE_FORMAT = 'DateFormat';
MythtvGadget._settings._datE_ON_NEWLINE = 'DateOnNewLine';
MythtvGadget._settings.defaulT_HEIGHT = 225;
MythtvGadget._settings.defaulT_DATE_FORMAT = 'dd MMM, HH:mm';
if (document.body.id === 'gadgetSettings') {
    ScriptFX.Application.current.run(MythtvGadget.SettingsScriptlet, null);
}

// ---- Do not remove this footer ----
// Generated using Script# v0.5.1.0 (http://projects.nikhilk.net)
// -----------------------------------
